//
//  SystemNewsViewCell.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/4/20.
//  Copyright © 2016年 game. All rights reserved.
//

#import "SystemNewsViewCell.h"
#import "TYAttributedLabel.h"
#import "NSString+HtmlCharact.h"

@interface SystemNewsViewCell ()
@property (weak, nonatomic) IBOutlet UIButton *head;

@property (weak, nonatomic) IBOutlet MBButtonWithFontAdapter *name;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *time;

@property (weak, nonatomic) IBOutlet TYAttributedLabel *content;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headHeight;
@property (weak, nonatomic) IBOutlet UILabel *footView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iamgeHeight;
@property (weak, nonatomic) IBOutlet UIImageView *backImage;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *footHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentHeight;
@end

@implementation SystemNewsViewCell

- (void)awakeFromNib {
    self.selectionStyle = 0;
    self.footView.backgroundColor = tabPlainBackColor;
    
    self.headHeight.constant = SCREEN_WIDTH*0.07;
    self.headWidth.constant = self.headHeight.constant;
    radius(self.head, self.headHeight.constant/2);
    
   self.backImage.image = [[UIImage imageNamed:@"bg_word"]stretchableImageWithLeftCapWidth:0 topCapHeight:10];
    
    self.footHeight.constant = SCREEN_HEIGHT*0.03;
    
}

-(void)setModel:(MyAddListModel *)model{
    _model = model;

    
    [self.head sd_setImageWithURL:[NSURL URLWithString:_model.avatar] forState:UIControlStateNormal];
    [self.name setTitle:_model.username forState:UIControlStateNormal];
    
    self.content.backgroundColor = [UIColor clearColor];
    
    self.time.text = _model.dateline;
    
    NSString *text = [_model.note filterresult];
//    NSArray *textArray = [text componentsSeparatedByString:@"\n"];
    
//    NSArray *colorArray = @[[UIColor lightGrayColor],textcolor];
    
//    NSInteger index = 0;
//    
//    for (NSString *text in textArray) {
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text];

        // 设置当前文本颜色
//        [attributedString addAttributeTextColor:colorArray[index%5]];
        
        // 设置当前文本字体
        [attributedString addAttributeFont:[UIFont systemFontOfSize:SCREEN_WIDTH*0.045]];
    
    
//        self.content.characterSpacing = 2;
    
        // 追加(添加到最后)属性文本
        [self.content setText:text];
//        [self.content appendText:@"\n"];
//        index++;
//    }
    
    [self.content sizeToFit];
    
    self.content.preferredMaxLayoutWidth = SCREEN_WIDTH-50;
    CGFloat Hhhh = [self.content getHeightWithWidth:SCREEN_WIDTH-50];
    
    self.contentHeight.constant = Hhhh;
    
    self.iamgeHeight.constant = Hhhh+30;
    self.cellHight = self.iamgeHeight.constant+SCREEN_HEIGHT*0.15;
}

- (IBAction)spaceGo:(UIButton *)sender {
}


-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    
    
}

@end
